package com.emily.test.controller;

import com.emily.test.controller.result.ResponseResult;
import com.emily.test.service.RedisService;
import com.emily.test.utils.ConstentUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @author ：zc
 * @date ：Created in 2019/4/9 14:42
 * @description：
 */
@Slf4j
@CrossOrigin(origins = "*", maxAge = 3600)
@RestController
@RequestMapping(value = "HaihuiApi")
@Api(value = "对外Api", description = "系统对接接口", position = 1, produces = MediaType.APPLICATION_JSON_VALUE)
public class HaihuiApi {
    @Autowired
    private RedisService redisService;
    @ApiOperation(value="获取合作伙伴列表", notes="根据公司code获取合作伙伴列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", required = true),
    })
    @PostMapping(value = "getUserInfo")
        public ResponseResult selectPartnerListByCode(@RequestParam(value = "token") String token){
        if(ConstentUtil.isEmpty(token)){
            log.info("token为空");
            return ResponseResult.fail("token为空");
        }
        try {
            Map<String, Object> userMap = (Map<String, Object>) redisService.get(token);
            log.info("查询成功{}",userMap.values());
            return ResponseResult.success(userMap);
        } catch (Exception e) {
            e.printStackTrace();
            return ResponseResult.fail("查询失败");
        }
    }
}
